package com.example.dianproject.repository;

import com.example.dianproject.entity.Meter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface MeterRepository extends JpaRepository<Meter, Long> {
    
    @Query("SELECT m FROM Meter m LEFT JOIN FETCH m.customer WHERE m.meterId = :meterId")
    Optional<Meter> findByIdWithCustomer(@Param("meterId") Long meterId);
    
    @Query("SELECT m FROM Meter m LEFT JOIN FETCH m.customer")
    List<Meter> findAllWithCustomer();
    
    boolean existsByMeterCode(String meterCode);
    
    boolean existsByMeterCodeAndMeterIdNot(String meterCode, Long meterId);
} 